<?php
     
class Attachment {
    
    public $content;
    public $title;
    public $to;
    public $message;
    
    public function mail() {
        
        $subject = 'Import this into kindle';
        $attachment = chunk_split(base64_encode($this->content));
        $filename = $this->title;
    
        $boundary = md5(date('r', time())); 
    
        $headers = "From: webmaster@ryan.com\r\nReply-To: webmaster@ryan.com";
        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
    
        $message="This is a multi-part message in MIME format.
    
    --_1_$boundary
    Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
    
    --_2_$boundary
    Content-Type: text/plain; charset=\"iso-8859-1\"
    Content-Transfer-Encoding: 7bit
    
    $this->message
    
    --_2_$boundary--
    --_1_$boundary
    Content-Type: application/octet-stream; name=\"$filename\" 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment 
    
    $attachment
    --_1_$boundary--";
    
        mail($this->to, $subject, $message, $headers);
        
        return true;
    }
}
?>
